package resilienceManager.qmul.gemom;
import no.geosoft.cc.geometry.Geometry;
import no.geosoft.cc.graphics.GObject;
import no.geosoft.cc.graphics.GPosition;
import no.geosoft.cc.graphics.GSegment;
import no.geosoft.cc.graphics.GStyle;
import no.geosoft.cc.graphics.GText;

/**
 * the nodeObject, used to draw the node in the scence
 * 
 * COPYRIGHT DISCLAIMER
 * Synopsis: All the source codes presented in this document are intellectual
 * properties of Queen Mary, University of London.
 * 
 * @year 2010
 * @author Peng Jiang, John Bigham, Jiayi Wu Jinfu Wang------------QMUL
 * @version 1.0 
 */


public class NodeObject extends GObject
{
	private NodeObject  parent_node;
	private RectObject  parent_rect;
	private double      x_, y_;
	private GSegment    circle_;
	private GSegment    line_;
	private double radius=50;

	private boolean isNode;


	NodeObject (String name, GObject parent, double x, double y, double r)
	{
		if(parent instanceof NodeObject)
		{
			parent_node=(NodeObject)parent;
			isNode=true;
		}
		else
		{
			if(parent instanceof RectObject)
			{
				parent_rect=(RectObject)parent;
				isNode=false;
			}
			else
			{
				parent_node=null;
				parent_rect=null;
			}
		}

		x_ = x;
		y_ = y;

		radius=50*r;

		line_ = new GSegment();
		addSegment (line_);

		circle_ = new GSegment();
		addSegment (circle_);

		circle_.setText (new GText (name, GPosition.MIDDLE));

		setStyle (new GStyle());

		parent.add (this);
	}


	double getX()
	{
		return x_;
	}


	double getY()
	{
		return y_;
	}

	public GSegment getSegment(){
		return circle_;
	}



	public void draw()
	{
		if ((parent_node != null)&&(isNode)) 
			line_.setGeometry (parent_node.getX(), parent_node.getY(), x_, y_);
		if ((parent_rect != null)&&(!isNode)) 
			line_.setGeometry (parent_rect.getX()+parent_rect.getW()/2, 
					parent_rect.getY()+parent_rect.getH(), x_, y_);
		

		circle_.setGeometryXy (Geometry.createCircle (x_, y_, radius));
	}
}

